<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>二维码控件</title>
    <script type="text/javascript" src="../internal.js"></script>
    <link rel="stylesheet" href="../../../bootstrap/bootstrap.css">
    <link rel="stylesheet" href="../../../bootstrap/bootstrap-responsive.css">
    <style type="text/css">
        * {
            color: #838383;
            margin: 0;
            padding: 0
        }

        html, body {
            font-size: 12px;
        }

        body {
            padding-left: 20px;
            padding-right: 20px;
        }
    </style>
</head>
<body>
<table class="table table-striped table-bordered" style="margin-top:18px;margin-bottom: 0;">
    <tr>
        <th><span>控件名称</span><span class="label label-important">*</span></th>
        <th><span>保存字段(用,号分隔)</span></th>
    </tr>
    <tr>
        <td>
            <input id="itemName" placeholder="必填项" type="text" size="20"/>
        </td>
        <td>
            <input id="itemList" type="text" size="20" title="二维码只支持少量中文，不要加入大量文本控件及图片控件"/>
        </td>
    </tr>
</table>
<script type="text/javascript">
    var oNode = null;
    window.onload = function () {
        //弹出窗口初始化函数，这里主要是判断是编辑下拉列表还是新增
        if (UE.plugins['qrcode'].editdom) {
            oNode = UE.plugins['qrcode'].editdom;
            $G('itemName').value = oNode.getAttribute('value');
            $G('itemList').value = oNode.getAttribute('datafld');
        }
    }
    dialog.oncancel = function () {
        if (UE.plugins['qrcode'].editdom) {
            delete UE.plugins['qrcode'].editdom;
        }
    };
    dialog.onok = function () {
        if ($G('itemName').value == '') {
            alert('控件名称不能为空');
            $G('itemName').focus();
            return false;
        }
        if (!oNode) {
            var sUrl = parent.getItemUrl;
            var nItemId = null;
            ajax.request(sUrl, {
                timeout: 60000, onsuccess: function (xhr) {
                    try {
                        nItemId = xhr.responseText;
                        oNode = document.createElement("img");
                        oNode.setAttribute('title', '二维码控件:' + $G('itemName').value.replace("\"", "&quot;"));
                        oNode.setAttribute('name', 'data_' + nItemId);
                        oNode.setAttribute('value', $G('itemName').value.replace("\"", "&quot;"));
                        oNode.setAttribute('class', 'qrcode');
                        oNode.setAttribute('datafld', $G('itemList').value);
                        oNode.setAttribute('className', 'qrcode');
                        oNode.setAttribute('src', './static/image/form/qrcode.gif');
                        editor.execCommand('insertHtml', oNode.outerHTML);
                        return true;
                    } catch (e) {
                        alert('插入控件出错，请联系OA管理员解决 ');
                        return false;
                    }
                }, onerror: function () {
                    alert('Request TimeOut');
                }
            });
        } else {
            oNode.setAttribute('value', $G('itemName').value.replace("\"", "&quot;"));
            oNode.setAttribute('title', '二维码控件:' + $G('itemName').value.replace("\"", "&quot;"));
            oNode.setAttribute('datafld', $G('itemList').value);
            delete UE.plugins['qrcode'].editdom; //使用后清空这个对象，变回新增模式
            return true;
        }
    };
</script>
</body>
</html>
